home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / misc / emu / QDOS2.lha / QLsource / ROMsrc / SYS / PROCESSOR_asm < prev    next >
Text File  |  1995-09-04  |  9KB  |  421 lines

  1. */beginfile PROCESSOR_asm
  2. ; --------------------------------------------------------------
  3. ; PROCESSOR_asm - QDOS processor specific routines
  4. ;           - last modified 04/08/95
  5. ; QDOS-Amiga sources by Rainer Kowallik
  6. ;    ...latest changes by Mark J Swift
  7. ;    ...68040/68060 changes by SNG, 16/8/94
  8. ; --------------------------------------------------------------
  9. ;*/beginoverlay
  10. ; -------------------------------------------------------------
  11. ;    check attn flags for 68000/008 processor. Returns Z if so
  12.  
  13. CHK6800X:
  14.     movem.l    d1/a6,-(a7)
  15.  
  16.     bsr    GET_ATTN
  17.     btst    #0,d1
  18.  
  19.     movem.l    (a7)+,d1/a6
  20.     rts
  21.  
  22. ; -------------------------------------------------------------
  23. ;    set attn flags for processor.
  24.  
  25. SET_ATTN:
  26.     movem.l    d0/a6,-(a7)
  27.  
  28.     move.l    a7,d1        ; Calculate start of
  29.     andi.w    #-$8000,d1    ; system variables
  30.     move.l    d1,a6
  31.  
  32.     bsr    ATTN_FLGS
  33.     move.w    d0,d1
  34.     move.w    d1,SV_IDENT+2(a6) ; set attn flags
  35.  
  36.     movem.l    (a7)+,d0/a6
  37.     rts
  38.  
  39. ; -------------------------------------------------------------
  40. ;    get attn flags for processor.
  41.  
  42. GET_ATTN:
  43.     movem.l    d0/a6,-(a7)
  44.  
  45.     move.l    a7,d1        ; Calculate start of
  46.     andi.w    #-$8000,d1    ; system variables
  47.     move.l    d1,a6
  48.     move.w    SV_IDENT+2(a6),d1 ; get attn flags
  49.  
  50.     movem.l    (a7)+,d0/a6
  51.     rts
  52.  
  53. ; -------------------------------------------------------------
  54. ;    create attention flags (check processor type)
  55.  
  56. ;    bit 0 - at least 68010
  57. ;    bit 1 - at least 68020
  58. ;    bit 2 - at least 68030
  59. ;    bit 3 - at least 68040
  60. ;    bit 4 - at least 68881 (possibly 68882)
  61. ;    bit 5 - 68882 present (or emulation)
  62. ;    bit 6 - 68040 or 68060 on-chip FPU enabled
  63. ;    bit 7 - at least 68060
  64. ;
  65. ; Note: If the MC68060 FPU has been turned off in software since
  66. ; the last reset (which enables it) bit 6 is zero, as if the FPU
  67. ; was not present and we were using an EC or LC processor.
  68. ;
  69. ATTN_FLGS:
  70.     movem.l    d1/a0-a3,-(a7)
  71.  
  72.     dc.w    $2078,$0010    ; move.l  $10.w,a0
  73.     dc.w    $2478,$002C    ; move.l  $2C.w,a2
  74.  
  75.     lea    LF80C18(pc),a1
  76.     dc.w    $21C9,$0010    ; move.l  a1,$10.w
  77.                 ; (ILLEGAL INSTRUCTION vector)
  78.     dc.w    $21C9,$002C    ; move.l  a1,$2C.w
  79.                 ; (F-LINE EMULATION vector)
  80.  
  81.     move.l    a7,a1
  82.  
  83.     moveq    #$0,d0        ; initialise attn flags
  84.     move.b    #0,161(a6)    ; ditto for QDOS
  85.  
  86.     dc.w    $4E7B,$0801    ; movec    d0,vbr
  87.     bset    #$0,d0        ; vbr present - 68010 at least
  88.  
  89. ;              Clear Data cache
  90. ;              | Freeze Data cache
  91. ;              | |Enable Data cache (off)
  92. ;              | ||    Clear Instruction cache
  93. ;              | ||    |  Enable Instruction cache
  94. ;              | ||    |  |
  95.     move.l    #%0000101000001001,d1
  96.  
  97.     dc.w    $4E7B,$1002    ; movec    d1,cacr
  98.     dc.w    $4E7A,$1002    ; movec    cacr,d1
  99.     bset    #$1,d0        ; cacr present - 68020 at least
  100.     move.b    #$20,161(a6)    ; store for QDOS
  101.  
  102.     btst    #$9,d1
  103.     beq.s    LF80BB4        ; no data cache - not a 68030
  104.  
  105.     bset    #$2,d0        ; definitely a 68030
  106.     move.b    #$30,161(a6)    ; store for QDOS
  107.  
  108. LF80BB4:
  109.     btst    #$0,d1
  110.     bne.s    LF80BDC        ; cacr present and (EI) bit
  111.                 ; operative - not a 68040
  112.  
  113.     or.w    #$C,d0        ; 68040 at least!
  114.     move.b    #$40,161(a6)    ; store for QDOS
  115.  
  116.     dc.w    $F4D8        ; CINVA ic/dc - inavalidate caches
  117. ;
  118. ; This code set up the TTR/ACU registers to stop data cacheing of memory
  119. ; in the first 16 Mb. This is not needed under Amiga Qdos as the cache is
  120. ; explicitly cleared when necessary after DMA,
  121. ;
  122. ; SNG    move.l    #$C040,d1    ; Serialize 0-16 Mb
  123. ; moved: dc.w    $4E7B,$1006    ; movec d1,(006)
  124.  
  125.     moveq    #0,d1        ; MMU off
  126.     dc.w    $4E7B,$1003    ; movec d1,TCR
  127.  
  128.     move.l    #$FFC000,d1    ; ACU/TTU off
  129.  
  130.     dc.w    $4E7B,$1007    ; movec d1,(007)
  131.     dc.w    $4E7B,$1004    ; movec d1,(004)
  132.     dc.w    $4E7B,$1005    ; movec d1,(005)
  133.     dc.w    $4E7B,$1006    ; movec d1,(006) - moved by SNG
  134.  
  135.     move.l    #$80008000,d1    ; Both caches on, for 040+
  136.     bra.s    SetCACR
  137.  
  138. LF80BDC:
  139. ;          Enable Instruction cache >=040 (1=ON)
  140. ;          | Write Allocation (1=ON)
  141. ;          | | Clear Data cache
  142. ;          | | |    Enable Data cache (1=ON)
  143. ;          | | |    |    Clear Instruction cache
  144. ;          | | |    |    |  Enable Instruction cache
  145. ;          | | |    |    |  |
  146.     move.l    #%1010100100001001,d1
  147.  
  148. SetCACR    dc.w    $4E7B,$1002    ; movec       d1,cacr
  149.  
  150.     btst    #$3,d0
  151.     beq.s    LF80BF6        ; skip if not a 68040 or later
  152. ;
  153. ; 68060 initialisation added here
  154. ;
  155. ; Note this tests the new PCR register to find out if we're on
  156. ; an 060. If this fails, the routine returns after checking for
  157. ; a 68040 FPU. Otherwise it turns on the 060 accelerators and
  158. ; reports the presence of an enabled FPU, if it finds one.
  159. ;
  160.     lea    NoPCR(pc),a3    ; Continuation if PCR absent
  161.     dc.w    $21CB,$0010    ; move.l  a3,$10.w
  162.                 ; (ILLEGAL INSTRUCTION vector)
  163.  
  164.     dc.w    $4E7A,$1808    ; 68060 PCR to D1 or illegal
  165.     swap    d1
  166.     cmp.w    #$0431,d1
  167.     beq.s    No60FPU        ; No FPU!
  168. ;    cmp.w    #$0430,d1    ; The only other possibility
  169. ;    bne.s    Unknown        ; at the time of writing...
  170.     btst    #17,d1        ; Test swapped DFP flag bit
  171.     bne.s    No60FPU        ; If FPU is disabled, leave off
  172.  
  173.     bset    #6,d0        ; Note 68060 FPU is available
  174.  
  175. No60FPU    bset    #7,d0        ; Set 060 bit in ATTN flags
  176.     move.b    #$60,161(a6)    ; Tell Qdos we're on an 060
  177.     swap    d1
  178.     bset    #0,d1        ; Ensure SOEP is on
  179.     dc.w    $4E7B,$1808    ; Store updated PCR
  180. ;
  181. ; Enable store buffer, code, data and (cleared) branch cache
  182. ;
  183.     move.l    #$A0C08000,d1    ; EDC+ESB+EBC+CABC+EIC
  184.     dc.w    $4E7B,$1002    ; movec       d1,cacr
  185.     bra.s    LF80C18
  186. ;
  187. ; The old code to check for the 040 FPU always failed because the
  188. ; 68040 does not support cpSAVE and cpRESTORE! Substitute FNOP
  189. ;
  190. ;    dc.w    $F327        ; cpSAVE
  191. ;    dc.w    $F35F        ; cpRESTORE
  192.  
  193. TryFPU    dc.w    $F280,0        ; FNOP sifts out ECs and LCs
  194.  
  195.     bset    #$6,d0        ; 68040 FPU present
  196.     bra.s    LF80C18
  197.  
  198. NoPCR    movea.l    a1,a7        ; Tidy stacked exception frame
  199.     bra.s    TryFPU
  200. ;
  201. ; Test for an off-CPU co-processor
  202. ;
  203. LF80BF6:
  204.     moveq    #$0,d1
  205.  
  206.     dc.w    $F201,$9000    ; FMOVE D1 to FPU
  207.     dc.w    $F201,$B000    ; FMOVE FPU to D1
  208.  
  209.     tst.l    d1        ; A most unlikely case
  210.     bne.s    LF80C18        ; Something strange has happened
  211.  
  212.     bset    #$4,d0        ; 68881 at least
  213.  
  214.     dc.w    $F327        ; cpSAVE -(A7)
  215.  
  216.     cmpi.b    #$18,$1(a7)    ; Check for 68882 frame
  217.     beq.s    LF80C16
  218.  
  219.     bset    #$5,d0        ; 68882 at least
  220.  
  221. LF80C16:
  222.     dc.w    $F35F        ; cpRESTORE (A7)+
  223.  
  224. LF80C18:
  225.     move.l    a1,a7        ; clean-up stack
  226.  
  227.     dc.w    $21C8,$0010    ; move.l  a0,$10.w
  228.     dc.w    $21CA,$002C    ; move.l  a2,$2C.w
  229.  
  230.     movem.l (a7)+,d1/a0-a3
  231.     rts
  232.  
  233. ; -------------------------------------------------------------
  234. ;  clear data and instruction caches
  235.  
  236. CLRALL:
  237.     movem.l    d0-d1/d4,-(a7)
  238.  
  239.     move.l    #$808,d1
  240.     bra.s    L0000C3E
  241.  
  242. ; -------------------------------------------------------------
  243. ;  clear data caches
  244.  
  245. CLRDATA:
  246.     movem.l    d0-d1/d4,-(a7)
  247.  
  248.     moveq    #$8,d1
  249.     rol.l    #8,d1
  250.  
  251. ; -------------------------------------------------------------
  252. ;  clear cache(s). d1=$800 - clear data cache
  253. ;         d1=$808 - clear data and instruction caches
  254.  
  255. ;         and on 68040/060 - update memory from caches
  256.  
  257. L0000C3E:
  258.     move.w    sr,-(a7)
  259.     ori.w    #$0700,sr    ; interrupts off
  260.  
  261.     exg    d1,d4
  262.     bsr    GET_ATTN
  263.     exg    d1,d4
  264.  
  265.     btst    #$1,d4        ; branch if '020 or more
  266.     bne.s    L0000C48
  267.  
  268.     ifd    ShoCach
  269.     move.l    d7,-(a7)
  270.     move.w    #$8000,d7
  271. WAITBLU:
  272.     move.w    #$000F,$DFF180
  273.     move.w    #0,$DFF180
  274.     dbra    d7,WAITBLU
  275.     move.l    (a7)+,d7
  276.     endif
  277.  
  278.     bra.s    CLRCACHEX    ; ...otherwise exit
  279.  
  280. L0000C48:
  281.     btst    #$3,d4
  282.     bne.s    L0000C68     ; '040 ?
  283. ;
  284. ; No explicit test for the 060 is needed as long as the 040
  285. ; bit remains set by tests on a 68060.
  286. ;
  287. ;    btst    #$7,d4        ; Check for '060
  288. ;    bne.s    L0000C68
  289.  
  290.     and.l    #$808,d1
  291.     ori    #$700,sr
  292.     dc.w    $4E7A,$0002    ; movec    cacr,d0
  293.     or.l    d1,d0
  294.     dc.w    $4E7B,$0002    ; movec    d0,cacr
  295.  
  296.     ifd    ShoCach
  297.     move.l    d7,-(a7)
  298.     move.w    #$8000,d7
  299. WAITRED:
  300.     move.w    #$0F00,$DFF180
  301.     move.w    #0,$DFF180
  302.     dbra    d7,WAITRED
  303.     move.l    (a7)+,d7
  304.     endif
  305.  
  306.     bra.s    CLRCACHEX
  307.  
  308. L0000C68:
  309.     btst    #$3,d1
  310.     bne.s    L0000C74
  311.  
  312.     dc.w    $F478        ; CPUSHA dc ('040 only)
  313.                 ; update memory from cache
  314.     bra.s    L0000C76
  315.  
  316. L0000C74:
  317.     dc.w    $F4F8        ; CPUSHA ic/dc ('040 only)
  318.                 ; update memory from caches
  319. L0000C76:
  320.     ifd    ShoCach
  321.     move.l    d7,-(a7)
  322.     move.w    #$8000,d7
  323. WAITGRN:
  324.     move.w    #$00F0,$DFF180
  325.     move.w    #0,$DFF180
  326.     dbra    d7,WAITGRN
  327.     move.l    (a7)+,d7
  328.     endif
  329.  
  330. CLRCACHEX:
  331.     move.w    (a7)+,sr
  332.     movem.l    (a7)+,d0-d1/d4
  333.     tst.l    d0
  334.  
  335.     rts
  336.  
  337. ; -------------------------------------------------------------
  338. ;  set bits in cacr d0=bits to set d1=bits to clear/alter
  339. ; This assumes 030 control register bits and tries to rework
  340. ; them for the 040. It fails, and won't suit 060 either. Luckily
  341. ; Mark says it is not used or needed in current Qdos versions.
  342.  
  343.     ifne    0        ; Ignore this code block
  344.  
  345. L0000C8E:
  346.     movem.l    d2-d4,-(a7)
  347.  
  348.     moveq    #$0,d3
  349.  
  350.     exg    d1,d4
  351.     bsr    GET_ATTN
  352.     exg    d1,d4
  353.  
  354.     btst    #$1,d4        ; exit if not at least '020
  355.     beq.s    L0000CAE
  356.  
  357.     and.l    d1,d0
  358.     or.w    #$808,d0     ; signal always clear caches
  359.     not.l    d1
  360.  
  361. L0000CB6:
  362.     ori    #$700,sr ; DODGY? Not restored later
  363.     dc.w    $4E7A,$2002    ; movec    cacr,d2
  364.     btst    #$3,d4
  365.     beq.s    L0000CD0     ; skip if not '040
  366. ;
  367. ; Attempts to convert 040 CACR to 030 form;
  368. ;
  369.  
  370.     move.l    d2,d3
  371.     andi.l    #$7FFF0000,d3    ; keep '060 bits...
  372.  
  373.                 ; mimick ED & EI
  374.  
  375.     swap    d2        ;        8000 8000
  376.     ror.w    #8,d2        ;        8000 0080
  377.     rol.l    #1,d2        ;        0000 0101
  378.     andi.w    #$0101,d2    ; ...only relevant bits
  379.  
  380.     move.w    d2,d3        ; mimick DBE & IBE
  381.     rol.w    #4,d3        ;        0000 1010
  382.     or.l    d3,d2        ;        0000 1111
  383.  
  384. L0000CD0:
  385.     move.l    d2,d3        ; cache register to d3
  386.     and.l    d1,d2        ; mask off changed bits
  387.     or.l    d0,d2        ; or in set bits
  388.     btst    #$3,d4
  389.     beq.s    L0000CEC     ; skip if not '040
  390.  
  391.                 ;        0000 0101
  392.     ror.l    #1,d2        ;        8000 0080
  393.     rol.w    #8,d2        ;        8000 8000
  394.     and.l    #$80008000,d2    ;
  395.  
  396.     swap    d3
  397.     or.w    d3,d2        ; keep '060 bits...
  398.     swap    d3
  399.     swap    d2        ;        8000 8000
  400.  
  401.     nop
  402.     dc.w    $F4F8        ; CPUSHA ic/dc ('040 only)
  403.                 ; update memory from caches
  404.  
  405. L0000CEC:
  406.     nop
  407.     dc.w    $4E7B,$2002    ; movec    d2,cacr
  408.     nop
  409.  
  410. L0000CAE:
  411.     move.l    d3,d0        ; return old bits in d0
  412.  
  413.     movem.l    (a7)+,d2-d4
  414.     rts
  415.  
  416.     endif            ; End of commented out lump
  417.  
  418. ;*/endoverlay
  419. ; --------------------------------------------------------------
  420. ;*/endfile
  421.